<?php

class Config
{
    static protected $_loadedKeys = array();

    static public function get($key)
    {
        if (!isset($loadedKeys[$key])) {
            $value = Db::getOneField('cf_value', 'config', "cf_key = '" . mysql_escape_string($key) . "'");
            self::$_loadedKeys[$key] = $value;
            return $value;
        }
        
        return self::$_loadedKeys[$key];
    }

    static public function set($key, $value)
    {
        $result = FALSE;
        $existed = Db::getOneField('Count(*)', 'config', 'cf_key="'.$key.'"');
        $cf_value = $value;
        if ($existed > 0)
        {
            eval(Db::update('config', 'cf_key=\''.$key.'\'', array_merge(array('cf_key','cf_note'))));
            if(mysql_affected_rows() > 0) {
                $result = TRUE;
            }
        }
        return $result;
    }
}